package vip.rssc.mybatis.controller;

import vip.rssc.mybatis.entity.TestUser;
import vip.rssc.mybatis.service.TestUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>Description: [TestUserController]</p >
 * Created on 2020年10月25日
 *
 * @author <a href="1014376159@qq.com">CJ</a>
 * @version 1.0
 * Copyright (c) 2020 cj
 */
@RestController("myTestUserController")
@RequestMapping("mybatis/user")
public class TestUserController {

    @Resource(name = "mybatisTestUserServiceImpl")
    private TestUserService testUserService;

    /**
     * localhost:8080/mybatis/user/save
     * {"name":"cj","age":4,"birthday":"2017-05-13","remark":""}
     * @param testUser
     */
    @PostMapping("save")
    public void save(@RequestBody TestUser testUser) {
        testUserService.save(testUser);
    }

    /**
     * localhost:8080/mybatis/user/get/1
     * @param id
     * @return
     */
    @GetMapping("get/{id}")
    public TestUser selectById(@PathVariable("id") Long id) {
        return testUserService.selectById(id);
    }

    /**
     * localhost:8080/mybatis/user/update
     * {"id":1,"name":"cj","age":2,"birthday":"2017-05-13","remark":""}
     * @param testUser
     */
    @PostMapping("update")
    public void updateById(@RequestBody TestUser testUser) {
        testUserService.updateById(testUser);
    }

    /**
     * localhost:8080/mybatis/user/select
     * @return
     */
    @GetMapping("select")
    public List<TestUser> selectList() {
        return testUserService.selectList();
    }

    /**
     * localhost:8080/mybatis/user/delete/1
     * @param id
     */
    @PostMapping("delete/{id}")
    public void deleteById(@PathVariable("id") Long id) {
        testUserService.deleteById(id);
    }

}
